package com.weiweiqin.weixin;

import com.weiweiqin.weixin.menu.*;
import com.weiweiqin.weixin.pojo.Token;
import com.weiweiqin.weixin.util.CommonUtil;
import com.weiweiqin.weixin.util.MenuUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 菜单管理器类
 * 
 * @author liufeng
 * @date 2013-10-17
 */
public  class MenuManager {
	private static Logger log = LoggerFactory.getLogger(MenuManager.class);

	/**
	 * 定义菜单结构
	 * 
	 * @return
	 */
	public static Menu getMenu() {
//		ClickButton btn11 = new ClickButton();
//		btn11.setName("开源中国");
//		btn11.setType("click");
//		btn11.setKey("oschina");
//
//		ClickButton btn12 = new ClickButton();
//		btn12.setName("ITeye");
//		btn12.setType("click");
//		btn12.setKey("iteye");
//
//		ViewButton btn13 = new ViewButton();
//		btn13.setName("CocoaChina");
//		btn13.setType("view");
//		btn13.setUrl("http://www.iteye.com");
//
//		ViewButton btn21 = new ViewButton();
//		btn21.setName("淘宝");
//		btn21.setType("view");
//		btn21.setUrl("http://m.taobao.com");
//
//		ViewButton btn22 = new ViewButton();
//		btn22.setName("京东");
//		btn22.setType("view");
//		btn22.setUrl("http://m.jd.com");
//
//		ViewButton btn23 = new ViewButton();
//		btn23.setName("唯品会");
//		btn23.setType("view");
//		btn23.setUrl("http://m.vipshop.com");
//
//		ViewButton btn24 = new ViewButton();
//		btn24.setName("当当网");
//		btn24.setType("view");
//		btn24.setUrl("http://m.dangdang.com");
//
//		ViewButton btn25 = new ViewButton();
//		btn25.setName("苏宁易购");
//		btn25.setType("view");
//		btn25.setUrl("http://m.suning.com");
//
//		ViewButton btn31 = new ViewButton();
//		btn31.setName("多泡");
//		btn31.setType("view");
//		btn31.setUrl("http://www.duopao.com");

//		ViewButton btn32 = new ViewButton();
//		btn32.setName("一窝88");
//		btn32.setType("view");
//		btn32.setUrl("http://www.yi588.com");
//		ViewButton btn1 = new ViewButton();
//		btn1.setName("");

		ComplexButton mainBtn1 = new ComplexButton();
		mainBtn1.setName("找兼职");
		mainBtn1.setType("view");
		mainBtn1.setUrl("http://www.renwuwu.com");
		mainBtn1.setSub_button(null);
		ViewButton btn1 = new ViewButton();
		btn1.setName("个人中心");
		btn1.setType("view");
		btn1.setUrl("http://www.renwuwu.com/meUser/mine");
//		ClickButton btn2 = new ClickButton();
//		btn2.setName("新手帮助");
//		btn2.setType("click");
//		btn2.setKey("help");
		ViewButton btn3 = new ViewButton();
		btn3.setName("联系客服");
		btn3.setType("view");
		btn3.setUrl("http://www.renwuwu.com/meUser/contact");
		ComplexButton mainBtn2 = new ComplexButton();
		mainBtn2.setName("我的");
		mainBtn2.setSub_button(new Button[] {btn1,btn3});
//		ComplexButton mainBtn2 = new ComplexButton();
//		mainBtn2.setName("购物");
//		mainBtn2.setSub_button(new Button[] { btn21, btn22, btn23, btn24, btn25 });
//		ComplexButton mainBtn3 = new ComplexButton();
//		mainBtn3.setName("我的");
//		mainBtn3.setSub_button(new Button[] { });

		Menu menu = new Menu();
		menu.setButton(new Button[] { mainBtn1,mainBtn2 });

		return menu;
	}

	public static void main(String[] args) {
		// 第三方用户唯一凭证
		String appId 		= "wxd75226638997e459";
		// 第三方用户唯一凭证密钥
		String appSecret 	= "1ae8a7861767e7279844b7589052386c";
		// 调用接口获取凭证
		Token token = CommonUtil.getToken(appId, appSecret);
		if (null != token) {
			boolean result = MenuUtil.createMenu(getMenu(), token.getAccessToken());
			if (result)
				log.info("菜单创建成功！");
			else
				log.info("菜单创建失败！");
		}
	}
}
